import java.util.PriorityQueue;
import java.util.Scanner;

public class Day_4_2_连续最大和 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            int[] arr = new int[n];
            for(int i = 0; i < n; i++){
                arr[i] = sc.nextInt();
            }
            int max = Integer.MIN_VALUE;
            int count = 0;
            for(int i = 0; i < n; i++){
                if(count <= 0){
                    count = arr[i];
                }else{
                    count += arr[i];
                }
                max = max > count ? max : count;
            }
            System.out.println(max);
        }
    }

    public int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> pq = new PriorityQueue<Integer>((a, b) -> b - a);
        for (int stone : stones) {
            pq.offer(stone);
        }

        while (pq.size() > 1) {
            int a = pq.poll();
            int b = pq.poll();
            if (a > b) {
                pq.offer(a - b);
            }
        }
        return pq.isEmpty() ? 0 : pq.poll();
    }

}
